Conditions | 2 |
Paths | 2 |
Total Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | import { nameFromDataIndex } from './getData'; |
||
7 | export const getColumnsFromStorage = (fromStorage, columns) => { |
||
|
|||
8 | |||
9 | const ret = []; |
||
10 | const foundValues = []; |
||
11 | |||
12 | fromStorage.forEach(col => { |
||
13 | |||
14 | const dataIndex = nameFromDataIndex(col); |
||
15 | const colFromProp = columns |
||
16 | .find(c => nameFromDataIndex(c) === dataIndex); |
||
17 | |||
18 | if (!colFromProp) { |
||
19 | return; |
||
20 | } |
||
21 | |||
22 | foundValues.push(dataIndex); |
||
23 | |||
24 | mappableProps.forEach(prop => { |
||
25 | |||
26 | if (col[prop] !== undefined) { |
||
27 | colFromProp[prop] = col[prop]; |
||
28 | } |
||
29 | }); |
||
30 | |||
31 | ret.push(colFromProp); |
||
32 | }); |
||
33 | |||
34 | if (foundValues.length !== columns.length) { |
||
35 | const unused = columns |
||
36 | .filter(c => foundValues.indexOf(nameFromDataIndex(c)) === -1); |
||
37 | ret.unshift.apply(ret, unused); |
||
38 | } |
||
39 | |||
40 | return ret; |
||
41 | }; |
||
42 |